var sortBy=function (filed,rev,primer){
    rev = (rev) ? -1 : 1;
    return function (a, b) {
      a = a[filed];
      b = b[filed];
      if (typeof (primer) != 'undefined') {
        a = primer(a);
        b = primer(b);
      }
      if (a < b) { return rev * -1; }
      if (a > b) { return rev * 1; }
      return 1;
    }
  }
function mathBy(a=6){	
    var arr = '';//容器
    for(var i =0;i<a;i++){
        var num = Math.random()*9;
        num = parseInt(num,10);
        arr += num;
    }
    return arr	
}
function formatDate(date, fmt) {
	if (/(y+)/.test(fmt)) {
		fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
	}
	let o = {
		'M+': date.getMonth() + 1,
		'd+': date.getDate(),
		'h+': date.getHours(),
		'm+': date.getMinutes(),
		's+': date.getSeconds()
	};
	for (let k in o) {
		if (new RegExp(`(${k})`).test(fmt)) {
			let str = o[k] + '';
			fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : padLeftZero(str));
		}
	}
	return fmt;
};
function padLeftZero(str) {
	return ('00' + str).substr(str.length);
}
module.exports.formatDate = formatDate;
module.exports.sortBy = sortBy;
module.exports.mathBy = mathBy;
